package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品接口")
@Slf4j
public class DishController {

    @Autowired
    private DishService dishService;

    @Autowired
    private RedisTemplate redisTemplate;


    //TODO 3-2-2 前端提交时失败，后端正常
    //TODO 7-2 清理缓存 未开发 因菜品信息无法展示，即无法操作修改、删除、启售与停售
    @PostMapping("/save")
    @ApiOperation("新增菜品")
    public Result save(@RequestBody DishDTO dishDTO) { //@RequestBody：因为前端请求的是json格式数据
        log.info("新增菜品：{}", dishDTO);
        dishService.saveWithFlavor(dishDTO);
        return Result.error(MessageConstant.UPLOAD_FAILED);
    }

    // TODO 3-3 前端显示为空，后端正常
    // TODO 3-4 菜品删除 3-5 菜品修改 未开发
    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public PageResult page(DishPageQueryDTO dishPageQueryDTO) {//前端请求的是在url里显示的参数，不用加@RequestBody
        log.info("菜品分页查询：参数为{}", dishPageQueryDTO);
        PageResult pageResult = dishService.pageQuery(dishPageQueryDTO);
        return pageResult;
    }

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    public Result<List<Dish>> list(Long categoryId){
        List<Dish> list = dishService.list(categoryId);
        return Result.success(list);
    }
}
